package com.fick.struts.action;

import org.apache.struts.actions.DispatchAction;

import com.fick.hibernate.dao.*;
import com.fick.hibernate.model.*;
import com.fick.tools.SystemLogger;
import com.fick.util.General;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Transaction;

public class ManageLogAction extends DispatchAction{
	
	private static final Log log = LogFactory.getLog(ManageLogAction.class);

	public ActionForward delLog(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		String id = request.getParameter("id");
		try{
			Syslog sl = new Syslog();
			SyslogDAO slDAO = new SyslogDAO();
			sl = slDAO.findById(Integer.valueOf(id));
			slDAO.delete(sl);
			request.setAttribute("message","删除成功");
			return mapping.findForward("logList");
		}catch(Exception e)
		{
			e.printStackTrace();
			log.error(e);
			SystemLogger.errorlog("1", "日志信息", "删除单个失败");
			return null;
		}
	}
	
	public ActionForward delAllLog(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		
		try{
			
			SyslogDAO slDAO = new SyslogDAO();
			Transaction ts = slDAO.getSession().beginTransaction();
			slDAO.getSession().createQuery("delete from Syslog").executeUpdate();
			ts.commit();
			request.setAttribute("message", "清空成功");
			return mapping.findForward("logList");
		}
		catch(Exception e)
		{
			e.printStackTrace();
			log.error(e);
			SystemLogger.errorlog("1", "日志信息", "清空日志失败");
			return null;
		}
		
		
	}
	

	
}
